home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 283_01 / sound.c < prev    next >
C/C++ Source or Header  |  1988-08-29  |  2KB  |  151 lines

  1.  
  2. #include "ciao.h"
  3.  
  4. /*
  5. **  sound generation primitives
  6. */
  7.  
  8. void setfrq( frequency ) unsigned frequency;
  9. {
  10.      static int C;
  11.      static long Hz = 1193180;
  12.  
  13.      C = Hz / frequency;
  14.      outp( 67, 182 );
  15.      outp( 66, C % 256 );
  16.      outp( 66, C / 256 );
  17. }
  18.  
  19.  
  20. void spkron()
  21. {
  22.      static int bits;
  23.  
  24.      bits = inp( 97 );
  25.      outp( 97, (char) (bits | 0x03) );
  26. }
  27.  
  28.  
  29. void spkroff()
  30. {
  31.      static int bits;
  32.  
  33.      bits = inp( 97 );
  34.      outp( 97, (char) (bits & 0xFC) );
  35. }
  36.  
  37.  
  38.  
  39. /*
  40. **  generate tone f for duration d
  41. **  f = 0 is silence for duration d
  42. */
  43.  
  44. void note( f,d ) unsigned f,d;
  45. {
  46.      if ( f > 0)
  47.      {
  48.         setfrq( f );
  49.         spkron();
  50.         while ( d-- > 0)
  51.         ;
  52.         spkroff();
  53.      }
  54.      else 
  55.      {
  56.         d = d = d;
  57.         while ( d-- > 0)
  58.         ;
  59.      }
  60. }
  61.  
  62.  
  63.  
  64.  
  65. /* 
  66. **  musical gadgets:
  67. **  all except thurb(), an error grumble, respond to the tone flag
  68. */
  69.  
  70.  
  71. int tone = 1;  /* controls whether the music gadgets make noise or not */
  72.  
  73.  
  74. void HIclack()
  75. {
  76.      if (tone)
  77.      {
  78.      note (  466, 38 );
  79.      note ( 1865, 27 );
  80.      note (  466, 60 );
  81.      note ( 1865, 30 );
  82.      note (  466, 28 );
  83.      note ( 1865, 17 );
  84.      }
  85. }
  86.  
  87.  
  88.  
  89. void LOclack()
  90. {
  91.      if (tone)
  92.      {
  93.      note (  392, 38 );
  94.      note ( 1568, 27 );
  95.      note (  392, 60 );
  96.      note ( 1568, 30 );
  97.      note (  392, 28 );
  98.      note ( 1568, 17 );
  99.      }
  100. }
  101.  
  102.  
  103. void bopbleet()
  104. {
  105.      if (tone)
  106.      {
  107.      note ( 587, 2000 );
  108.      note ( 784, 4000 );
  109.      note ( 880, 2000 );
  110.      }
  111. }
  112.  
  113.  
  114. void blopbloop()
  115. {
  116.      if (tone)
  117.      {
  118.      note ( 392, 4000 );
  119.      note ( 440, 2000 );
  120.      note ( 294, 2000 );
  121.      }
  122. }
  123.  
  124.  
  125. void thurb()
  126. {
  127.      note (  46, 250 );
  128.      note ( 185, 600 );
  129.      note ( 740, 350 );
  130.      note (  46, 150 );
  131.      note ( 185, 800 );
  132.      note ( 740, 250 );
  133.      note (  46, 250 );
  134.      note ( 185, 600 );
  135.      note ( 740, 350 );   /* 3200 */
  136.  
  137.      note (  46, 250 );
  138.      note ( 185, 600 );
  139.      note ( 740, 350 );
  140.      note (  46, 400 );
  141.      note ( 185, 400 );
  142.      note ( 740, 400 );
  143.      note (  46, 250 );
  144.      note ( 185, 600 );
  145.      note ( 740, 350 );  /* 6400 */
  146.  
  147.      note (  98, 1600 ); /* 8000 */
  148. }
  149.  
  150.  
  151.